package Unite;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class LegionTest {
   
   Legion legion;
   private Unit _archer;
   private Unit _chevalier;
   private Unit _toruk;
   private Unit _guerrier;

   @Before
   public void setUp() {
      _archer = FactoryUnit.CreateUnit(Unit.ARCHER, new AttributeMap(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), 0);
      _chevalier = FactoryUnit.CreateUnit(Unit.CHEVALIER, new AttributeMap(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), 0);
      _toruk = FactoryUnit.CreateUnit(Unit.TORUK, new AttributeMap(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), 0);
      _guerrier = FactoryUnit.CreateUnit(Unit.GUERRIER, new AttributeMap(5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5), 0);
      legion = new Legion(null);
   }
   
   @After
   public void tearDown() {
	   _archer = null;
	   _chevalier = null;
	   _toruk = null;
	   _guerrier = null;
	   legion = null;
   }

   @Test
   public void test() {
      legion.add(_archer.getCopy());
      legion.add(_archer.getCopy());
      double expectedResult = _archer.getWeight() + _archer.getWeight();
      assertTrue("Value of " + legion.getWeight() + " instead of " + expectedResult, legion.getWeight() == expectedResult);
   }
   
   @Test
   public void testSplitLegion() {
	  legion.add(_archer.getCopy());
      legion.add(_archer.getCopy());
      legion.add(_archer.getCopy());
      legion.add(_chevalier.getCopy());
      legion.add(_chevalier.getCopy());
      legion.add(_toruk.getCopy());
      legion.add(_toruk.getCopy());
      legion.add(_toruk.getCopy());
      legion.add(_toruk.getCopy());
      legion.add(_guerrier.getCopy());
      
      Legion legionSplit = legion.splitLegion();
      assertEquals(legion.getUnits().size(),4);
      assertEquals(legion.getAllUnitsMap().get(_archer.getClasseId()).size(),1);
      assertEquals(legion.getAllUnitsMap().get(_chevalier.getClasseId()).size(),1);
      assertEquals(legion.getAllUnitsMap().get(_toruk.getClasseId()).size(),2);
      assertEquals(legion.getAllUnitsMap().get(_guerrier.getClasseId()).size(),0);
      assertEquals(legionSplit.getUnits().size(),6);
   }
   

}
